package com.my.mvvmrapid.ui.main.fragment.homeshop.shopother;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.my.mvvmrapid.BR;
import com.my.mvvmrapid.MyApplication;
import com.my.mvvmrapid.R;
import com.my.mvvmrapid.databinding.FragmentHomeShopOtherBinding;
import com.my.mvvmrapid.ui.main.fragment.homeshop.shoptest.adapter.ListAdapter;
import com.my.mvvmrapid.view.CustomRefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.zhongjh.mvvmrapid.base.ui.BaseFragment;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhongjh on 2021/4/12.
 */
public class HomeShopOtherFragment extends BaseFragment<FragmentHomeShopOtherBinding, HomeShopOtherViewModel> {

    public static HomeShopOtherFragment newInstance() {
        return new HomeShopOtherFragment();
    }

    @Override
    public int initContentView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_home_shop_other;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {

    }

    @Override
    public void initData() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add("Item" + i);
        }
        ListAdapter adapter = new ListAdapter(getActivity(), list);
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        binding.recyclerView.setAdapter(adapter);

        binding.refreshLayout.setDragRate(1F);
        binding.refreshLayout.setRefreshHeader(new CustomRefreshHeader(getActivity()));
        binding.refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                binding.refreshLayout.finishLoadMore(2000);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                binding.refreshLayout.finishRefresh(2000);
            }
        });
    }

    @Override
    public void initViewObservable() {

    }
}
